#include "Tester.h"
#include <dirent.h>
#include <errno.h>
#ifdef linux
   #include <sys/time.h> //Basically this doesn't work on windows.
#else
   #include "Wintime.h"
#endif
#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long Tester::getTime() const {
  timeval time;
  gettimeofday(&time, 0);
  return time.tv_sec * 1000 + time.tv_usec / 1000;
}

std::vector<std::string> Tester::listFolder(const std::string &dir) {
  vector<string> files;

  DIR *dp;
  struct dirent *dirp;
  if((dp  = opendir(dir.c_str())) == NULL) {
    cout << "Error(" << errno << ") opening " << dir << endl;
    return files;
  }

  while ((dirp = readdir(dp)) != NULL) {
    string file(dirp->d_name);
    if ((file.find(".heap") != string::npos ||
          file.find(".dijkstra") != string::npos)
        && file[0] != '.')
      files.push_back(dir + string(dirp->d_name));
  }
  closedir(dp);

  std::sort(files.begin(), files.end());
  return files;
}

